home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS Toolkit
/
BBS Toolkit.iso
/
doors_1
/
doorskl3.zip
/
DOORHELP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-12-05
|
4KB
|
200 lines
/*
* Help functions for doorskel. Note that these functions are untested in
* this configuration; they were lifted from XDB (so they do work).
* these are provided to help you produce slick Doors.
*/
#include "doorskel.h"
#define MAXHELPS 115
#define YESNOM 15
static int hp = 0;
static int ch = 0;
static struct helps {
char hname[9];
int h;
long hptr;
} hps [MAXHELPS + 1];
int helpfp = -1;
char helpname[MAXDIR];
void _fastcall getline(char *lineh);
char * _fastcall fgetsx (char *str,unsigned int num,unsigned int handle);
/******************************************
help file format:
<topic>
help text (may be several lines) for topic
<next topic>
help text for this topic
...
<end>
To use: call load_help() at program beginning (insert early in mainloop())
Thereafter, use set_help() to establish the current topic and help() to
display help on the current topic.
********************************************/
/* Load the HELP! definition file */
void _fastcall load_help (char *hn) { /* hn is filename (ex. Door.hlp) */
char lineh[81],*p;
if(!strchr(hn,':') && !strchr(hn,'/') && !strchr(hn,'\\')) {
p = searchpath(hn);
if(!p) p = hn;
}
else p = hn;
if (!strcmp(helpname,p)) return; /* already loaded */
strcpy(helpname,p);
if((helpfp = sopen(helpname,O_RDONLY | O_BINARY,SH_DENYNO)) == -1) return;
getline(lineh);
for(;;) {
if(hp == MAXHELPS) break;
if(!strncmp(lineh,"<end>",5)) break;
if(*lineh != '<') continue;
strncpy(hps[hp].hname,lineh+1,8);
hps[hp].hptr = tell(helpfp);
getline(lineh);
while (*lineh != '<') {
hps[hp].h++;
getline(lineh);
}
hp++;
}
close(helpfp);
}
/* Get a line of text from the help file */
static void _fastcall getline (char *lineh) {
if(!fgetsx(lineh,80,helpfp)) strcpy(lineh,"<end>");
}
/* Set the current active help topic */
void _fastcall set_help (char *s) { /* s is name of topic */
for (ch = 0;ch < hp;ch++) if(!strncmp(s,hps[ch].hname,8)) break;
}
/* Display the current help text */
void _fastcall help (void) {
char ln[80];
int i,cntr = 0;
if((helpfp = sopen(helpname,O_RDONLY | O_TEXT,SH_DENYNO)) == -1) return;
if (hp && ch != hp) {
printm("\r\n -=HELP=-\r\n");
lseek(helpfp,hps[ch].hptr,0);
for(i = 0;i < hps[ch].h;i++) {
getline(ln);
stripcr(ln);
rstrip(ln);
printfm("%s\r\n",ln);
cntr++;
if(cntr > numlines - 2) {
printm("More? (Y/n) ");
if(*genin(1,0,1,1,YESNOM) != 'N') {
printm("\b \b \b \b \b \b \b \b \b \b \b \b");
}
cntr = 0;
}
}
hitreturn();
}
close(helpfp);
}
/* An fgets() for shared i/o */
char * _fastcall fgetsx (char *str,unsigned int num,unsigned int handle) {
char *p;
long pos;
unsigned int x;
if (eof(handle)) {
*str = 0;
return NULL;
}
pos = tell(handle);
x = read(handle,str,num - 1);
if (x < 1) {
*str = 0;
return NULL;
}
str[x] = 0;
p = str;
while(*p && *p != '\r' && *p != '\n') p++;
if(!*p) return str;
if(*p == '\r') {
*p = '\n';
if (p[1] == '\n') {
p++;
*p = 0;
}
}
p++;
*p = 0;
lseek(handle,pos+((long)p - (long)str),SEEK_SET);
return str;
}
#ifdef FFPRINTF
#define MAX_BUFFER_LENGTH 641
/* An fprintf() for shared i/o
included this as, together with fgetsx above, it allows you
to use sopen() and shared/lockable i/o with most of the
stream conveniences. ignore this otherwise */
unsigned int _cdecl ffprintf (unsigned int handle,char *string,...) {
unsigned int x;
char *buffer;
va_list pArguments;
buffer = calloc(MAX_BUFFER_LENGTH, sizeof(char));
if(!buffer) {
return 0;
}
va_start(pArguments,string);
x = vsprintf(buffer,string,pArguments);
va_end(pArguments);
write(handle,buffer,x);
free(buffer);
return x;
}
#endif
/* end doorhelp.c */